﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;

namespace HYSoft.Web.Ashx
{
    /// <summary>
    /// sensornode 的摘要说明
    /// </summary>
    public class sensornode : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            // context.Response.ContentType = "text/html";
            try
            {
                StringBuilder sb = new StringBuilder();
                //传感器的绑定
                string sql = " [index]!=0";
                DataTable dt = new BLL.sensor_node().GetList(sql).Tables[0];
                if (dt == null)
                    return;
                if (dt.Rows.Count == 0)
                {
                    return;
                }
                else
                {
                    sb.Append("[");
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        sb.Append("{\"adminno\":\"" + dt.Rows[i]["adminno"].ToString() + "\",\"name\":\"" + dt.Rows[i]["name"].ToString() + "\"},");
                    }

                    sb.Remove(sb.Length - 1, 1);
                    sb.Append("]");
                }
                context.Response.ContentType = "application/json";
                context.Response.ContentEncoding = Encoding.UTF8;
                context.Response.Write(sb.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}